package com.yunfeng.supercall.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ly.library.stickyadpter.BaseStickyListAdapter;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.yunfeng.supercall.R;
import com.yunfeng.supercall.bean.ContactsBaseBean;
import com.yunfeng.supercall.manager.SuperFriendsManager;

public class SuperFriendsAdapter extends BaseStickyListAdapter<ContactsBaseBean> {
	
	DisplayImageOptions options;
	
	public SuperFriendsAdapter(Context context, List<ContactsBaseBean> list) {
		super(context, list);
		// TODO Auto-generated constructor stub
		options = new DisplayImageOptions.Builder()
		.displayer(new RoundedBitmapDisplayer(8))
		.cacheInMemory(true)
		.cacheOnDisk(true)
		.considerExifParams(true)
		.bitmapConfig(Bitmap.Config.RGB_565)
		.build();
	}

	
	
	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return getItem(position).getContactsType();
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 3;
	}

	@Override
	public View initView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ContactsBaseBean base = getItem(position);
		int type = base.getContactsType();
		if (convertView == null) {
			switch (type) {
			case ContactsBaseBean.TYPE_NORMAL_CONTACTS:
				convertView = getInflater().inflate(
						R.layout.list_item_super_friends, null);
				break;
			case ContactsBaseBean.TYPE_SUPER_CONTACTS:
				convertView = getInflater().inflate(
						R.layout.list_item_super_friends, null);
				break;
			case ContactsBaseBean.TYPE_SYSTEM_CONTACTS:
				convertView = getInflater().inflate(
						R.layout.list_item_system_super_friends, null);
				break;
			}
		}
		ContactsBaseBean.setupSingleLineContactsView(convertView, base);
		if (getItemViewType(position) == ContactsBaseBean.TYPE_SYSTEM_CONTACTS) {
			View red = ViewHolder.get(convertView, R.id.red_dot);
			if (position == 0) {
				boolean has = SuperFriendsManager.hasNewFriend(getContext());
				red.setVisibility(has ? View.VISIBLE : View.INVISIBLE);
			} else {
				red.setVisibility(View.INVISIBLE);
			}
		}
		
		
		
		return convertView;
	}

	@Override
	public View getHeaderView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (position == 0) {
			return new View(getContext());
		} else {
			convertView = getInflater().inflate(
					R.layout.list_sticky_header_text, parent, false);
			TextView tv = (TextView) convertView;
			if (position == 0 || position == 4 || position == 1) {
				tv.setText("");
			} else {
				tv.setText(getItem(position).getStickyItem());
			}

			return convertView;
		}

	}
}
